Skip to content

Resolve package self-imports, directory imports, and values over same-named types - #727

Open
jaywyawhare wants to merge 1 commit into
hydra-db:bench/code-corpusfrom
jaywyawhare:fix/resolve-self-imports
Open

jaywyawhare wants to merge 1 commit into
hydra-db:bench/code-corpusfrom
jaywyawhare:fix/resolve-self-imports

Conversation

@jaywyawhare

@jaywyawhare jaywyawhare commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Resolve three kinds of calls the indexer missed or got wrong: a package root importing itself by name, TypeScript imports of . and .., and calls that linked to a type sharing its name with the function or const they call. Stacked on #724, which adds the corpus these figures come from.

Implementation details

Decisions

  • A root holding __init__.py also resolves its modules under the root folder's own name, so from sanic.cli.app import SanicCLI works with sanic/ as the root. This is a packages entry in the Python module table.
  • Bare . and .. in JS and TS imports count as relative and reach the folder's index file, the root folder included.
  • A call links to the value (function or const), never to an interface or type alias of the same name. Type positions still pick the type.
  • A shared fixture, tests/fixtures/code-self, drives tests in both SDKs and a new code_self conformance case.

Results on the pinned corpus (precision / recall, %)

Root Before After
sanic 100 / 52.7 100 / 90.9
rich 99.9 / 83.8 99.9 / 94.5
typer 100 / 91.6 100 / 96.0
zod 95.9 / 82.4 100 / 85.9
hono 99.7 / 63.9 99.8 / 75.1

The other roots are unchanged. Python and TypeScript produce identical call edges on all 11 roots.

Validation

  • The new tests fail on base and pass here.
  • scripts/precheck.py passes (215 changed lines, clean trial merge).
  • Code-index tests in both SDKs and the conformance test pass on Kuzu.

Limits

The package name comes from the root folder's name only; parents outside the root are not consulted.

Linked issue

Closes #725

AI Assistance

AI tools helped write and test parts of this. I reviewed and ran every change.

Checklist

  • Implements an issue a maintainer has /approved.
  • Small and scoped to that issue.
  • New errors have a code and hint, the same on API, CLI, and MCP in both SDKs (see AGENTS.md). No new codes.
  • Breaking changes described below, or none.

Breaking changes

None. Some calls that resolved to nothing now get a CALLS or CONSTRUCTS edge, and zod-style calls now link to the value instead of the same-named type.


See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@arrry-hydraDB arrry-hydraDB added bug Wrong behaviour area: parity Python vs TypeScript, conformance effort: S Under ~50 lines, one place labels Dec 5, 2026

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this

bases = [(f.root, "/".join(parts[: len(parts) - dots + 1]))]
path = text[dots:].replace(sep, "/")
elif relative or text.startswith(("./", "../")):
elif relative or text.startswith(("./", "../")) or text in (".", ".."):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bare "." (and "..", same code) becomes the folder path and then the file suffixes are tried before /index.*, so a sibling file named after the folder wins.

Repro: web/sub.ts and web/sub/index.ts both export wrong; web/sub/use.ts has import { wrong } from "."; wrong(). Both SDKs give CALLS function:web/sub/use.ts:go -> function:web/sub.ts:wrong. ts.resolveModuleName resolves it to web/sub/index.ts under Node10, Node16 and Bundler.

For . and .. only try the /index.* suffixes. Please add the sibling file to the code-self fixture so the test covers it.

bases = [[f.root, parts.slice(0, parts.length - dots + 1).join("/")]];
path = text.slice(dots).split(sep).join("/");
} else if (relative || text.startsWith("./") || text.startsWith("../")) {
} else if (relative || text.startsWith("./") || text.startsWith("../") || text === "." || text === "..") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix needed here for . and ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: parity Python vs TypeScript, conformance bug Wrong behaviour effort: S Under ~50 lines, one place

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants